Back to course home
0% completed
Vote For New Content
Oracle Hard
Integer to English Words (hard)
Solution: Integer to English Words
Trapping Rain Water (hard)
Solution: Trapping Rain Water
First Missing Positive (hard)
Solution: First Missing Positive
Merge K Sorted Lists (hard)
Solution: Merge K Sorted Lists
Max Points on a Line (hard)
Solution: Max Points on a Line
Sudoku Solver (hard)
Solution: Sudoku Solver
Longest Valid Parentheses (hard)
Solution: Longest Valid Parentheses
Remove Nth Node From End of List (Medium)
Solution: Remove Nth Node From End of List
Median of Two Sorted Arrays (hard)
Solution: Median of Two Sorted Arrays
Constrained Subsequence Sum (hard)
Solution: Constrained Subsequence Sum
Binary Tree Right Side View (medium)
Problem Statement
Given a root of the binary tree, return an array containing nodes in its right view.
The right view of a binary tree consists of nodes that are visible when the tree is viewed from the right side. For each level of the tree, the last node encountered in that level will be included in the right view.
Examples
Example 1
- Input: root =
[1, 2, 3, 4, 5, 6, 7]
- Expected Output:
[1, 3, 7] - Justification:
- The last node at level 0 is 1.
- The last node at level 1 is 3.
- The last node at level 2 is 7.
Example 2
- Input: root =
[12, 7, 1, null, 9, 10, 5, null, 3]
- Expected Output:
[12, 1, 5, 3] - Justification:
- The last node at level 0 is 12.
- The last node at level 1 is 1.
- The last node at level 2 is 5.
- The last node at level 3 is 3.
Example 3
- Input: root =
[8, 4, 9, 3, null, null, 10, 2]
- Expected Output:
[8, 9, 10, 2] - Justification:
- The last node at level 0 is 8.
- The last node at level 1 is 9.
- The last node at level 2 is 10.
- The last node at level 3 is 2.
Constraints:
- The number of nodes in the tree is in the range
[0, 100]. -100 <= Node.val <= 100
Try it yourself
Try solving this question here:
Java
. . . .
Solution: Combination Sum
Solution: Binary Tree Right Side View
Mark as Completed
On this page
Problem Statement
Examples
Try it yourself